﻿#include "pch.h"
#include "WindowsInput.h"

#include "GameEngine.h"
#include <GLFW/glfw3.h>

namespace Engine
{
	AbstractInput* AbstractInput::instance = new WindowsInput();

	bool WindowsInput::IsMouseButtonImpl(int button)
	{
		GLFWwindow* window = static_cast<GLFWwindow*>(GameEngine::GetInstance().GetWindow().GetNativeWindow());
		const int state = glfwGetMouseButton(window, button);
		return state == GLFW_PRESS;
	}

	float WindowsInput::GetMouseXImpl()
	{
		/*GLFWwindow* window = static_cast<GLFWwindow*>(GameEngine::GetInstance().GetWindow().GetNativeWindow());
		double xpos;
		double ypos;
		glfwGetCursorPos(window, &xpos, &ypos);
		return (float)xpos;*/

		auto [xPos, yPos] = GetMousePosition();
		return xPos;
	}

	float WindowsInput::GetMouseYImpl()
	{
		/*GLFWwindow* window = static_cast<GLFWwindow*>(GameEngine::GetInstance().GetWindow().GetNativeWindow());
		double xpos;
		double ypos;
		glfwGetCursorPos(window, &xpos, &ypos);
		return (float)ypos;*/

		auto [xPos, yPos] = GetMousePosition();
		return yPos;
	}

	std::pair<float, float> WindowsInput::GetMousePositionImpl()
	{
		GLFWwindow* window = static_cast<GLFWwindow*>(GameEngine::GetInstance().GetWindow().GetNativeWindow());
		double x_pos;
		double y_pos;
		glfwGetCursorPos(window, &x_pos, &y_pos);
		// return std::pair<float, float>(xPos, yPos);
		return { static_cast<float>(x_pos), static_cast<float>(y_pos) };
	}

	bool WindowsInput::IsKeyPressedImpl(int keyCode)
	{
		GLFWwindow* window = static_cast<GLFWwindow*>(GameEngine::GetInstance().GetWindow().GetNativeWindow());
		const int state = glfwGetKey(window, keyCode);
		return state == GLFW_PRESS || state == GLFW_REPEAT;
	}
}
